<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>serializeForm</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .form {
            padding: 15px;
            width: 450px;
            margin: 15px auto;
        }

        .form-input {
            position: relative;
            margin-bottom: 15px;
        }

        .form-label {
            width: 100px;
            text-align: right;
            color: rgba(0, 0, 0, .85);
            display: inline-block;
        }

        .form-input {
            display: inline-block;
            width: calc(100% - 120px);
            margin-left: 10px;
            border: 1px solid #e2e2e2;
            border-radius: 4px;
            outline: none;
            transition: all .3s cubic-bezier(0.075, 0.82, 0.165, 1);
            color: rgba(0, 0, 0, .85);
            padding: 10px 12px;
        }

        .form-input:focus {
            border-color: #2396ef;
        }

        .form-item:last-child {
            text-align: center;
        }

        .form-btn {
            display: inline-block;
            padding: 8px 15px;
            outline: none;
            border-radius: 8px;
            border: 1px solid #ebebeb;
            background-color: transparent;
            color: rgba(0, 0, 0, .85);
            transition: all .3s cubic-bezier(0.075, 0.82, 0.165, 1);
        }

        .form-btn:hover {
            border-color: #2396ef;
            color: #2396ef;
            cursor: pointer;
        }

        .form-data-content {
            color: rgba(0, 0, 0, .85);
            padding: 10px;
            font-size: 25px;
            text-align: center;
        }
    </style>
</head>

<body>
    <form id="form" class="form">
        <div class="form-item">
            <label class="form-label">昵称:</label>
            <input type="text" class="form-input" placeholder="请输入昵称" name="nickname" value="夕水">
        </div>
        <div class="form-item">
            <label class="form-label">密码:</label>
            <input type="password" name="password" class="form-input" placeholder="请输入密码" value="123456">
        </div>
        <div class="form-item">
            <button type="button" class="form-btn">提交</button>
        </div>
    </form>
    <p id="formDataContent" class="form-data-content"></p>
    <script>
        const serializeForm = form => Array.from(new FormData(form), field => field.map(decodeURIComponent).join('=')).join('&');
        const submit = document.querySelector('.form-btn');
        const form = document.querySelector('.form');
        const formContent = document.querySelector('.form-data-content');
        submit.addEventListener('click', () => {
            formContent.textContent = serializeForm(form);
        })
    </script>
</body>

</html>